/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rafkind.raytracer;

/**
 *
 * @author drafkind
 */
public class Camera {
  private Vector3 position;
  private Matrix3 matrix;

  private int imageWidth;
  private int imageHeight;
  private double tanFovX;
  private double tanFovY;

  public Camera() {    
  }

  private void recalculateCameraParameters() {
    double fovx = Math.PI / 4.0;
    tanFovX = Math.tan(fovx);

    if (imageWidth != 0) {
      double fovy = imageHeight * Math.PI / (4.0 * imageWidth);
      tanFovY = Math.tan(fovy);
    }
  }
  
  public Ray createRay(int u, int v) {
    double x = tanFovX * (double)(2 * u - getImageWidth()) / (double)(getImageWidth());
    double y = -tanFovY * (double)(2 * v - getImageHeight()) / (double)(getImageHeight());

    Ray baseRay = Ray.createPositionally(new Vector3(0, 0, 0), new Vector3(x, y, 1));

    return baseRay;
  }

  public int getImageHeight() {
    return imageHeight;
  }

  public void setImageHeight(int imageHeight) {
    this.imageHeight = imageHeight;
    recalculateCameraParameters();
  }

  public int getImageWidth() {
    return imageWidth;
  }

  public void setImageWidth(int imageWidth) {
    this.imageWidth = imageWidth;
    recalculateCameraParameters();
  }

  public Vector3 getPosition() {
    return position;
  }

  public void setPosition(Vector3 position) {
    this.position = position;
  }
}